package com.siwei.infoextract.wrapper.parser;

import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.html.HTMLEditorKit.ParserCallback;

public class InternalConverter extends ParserCallback {
	private DomNode head = null;

	private DomNode current = null;
	private DomNode parent = null;
	private int ignoreCount = 0;

	public InternalConverter() {
		head = parent = new DomNode(Constraints.ROOT_TAG_NAME, "");
	}

	public void handleEndTag(Tag t, int pos) {
		super.handleEndTag(t, pos);
		parent = parent.getParent();
	}

	public void handleSimpleTag(Tag t, MutableAttributeSet a, int pos) {
		super.handleSimpleTag(t, a, pos);

		// We don't hanlde simple tag as simple tag doesn't contain information
		//
	}

	public void handleStartTag(Tag t, MutableAttributeSet a, int pos) {
		super.handleStartTag(t, a, pos);
		current = new DomNode(t.toString(), a.toString());
		parent.addChild(current);
		parent = current;
	}

	public void handleText(char[] data, int pos) {
		super.handleText(data, pos);
		parent.addChild(new DomNode(Constraints.TEXT_TAG_NAME, new String(data)));
	}

	public DomNode GetDomTreeRoot() {
		return head;
	}
}
